<?php

namespace app\shopapi\controller;


use app\api\model\ExtendConsume;
use app\api\model\shop\ShopFans;
use app\api\model\UserConsumeLog;
use app\common\controller\Shopapi;
use app\common\library\Ems;
use app\common\library\Sms;
use app\shopapi\model\ExtendConsumeShop;
use app\shopapi\model\MoneyLog;
use app\shopapi\model\ShopSound;
use app\shopapi\model\ShopUser;
use fast\Random;
use think\Config;
use think\Validate;

/**
 * 音响接口
 */
class Sound extends Shopapi
{
    protected $noNeedLogin = ['cancel','pay'];
    protected $noNeedRight = '*';

    public function cancel()
    {
        try {
            $shop_id = input('shop_id',0);

            $model = new \app\shopapi\model\Sound();
            //$res = $model->singleInvoke('收款100万元','H810D2408020101');
            $res = $model->cancelMultiInvoke('用户取消支付',$shop_id);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('',$res);
    }

    public function pay()
    {
        try {
            $shop_id = input('shop_id',0);

            $model = new \app\shopapi\model\Sound();
            //$res = $model->singleInvoke('收款100万元','H810D2408020101');
            $res = $model->multiInvoke(20,$shop_id);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('',$res);
    }

    //添加设备
    public function add()
    {
        $device_id = input('device_id','');



        $shop_sound_model  = new ShopSound();

        $data = [
            'device_id'=>$device_id,
            'shop_id'=>$this->shopauth->shop_id,

        ];

        $res = $shop_sound_model->save($data);
        if ($res){
            $this->success('添加成功');
        } else {
            $this->error('添加失败');
        }
    }

    //编辑设备
    public function edit()
    {
        $device_id = input('device_id','');
        $id = input('id',0);
        $shop_sound_detail  = ShopSound::get($id);

        $data = [
            'device_id'=>$device_id,
        ];

        $res = $shop_sound_detail->save($data);
        if ($res){
            $this->success('编辑成功');
        } else {
            $this->error('编辑失败');
        }
    }

    //删除设备
    public function del()
    {
        $id = input('id',0);
        $shop_sound_detail  = ShopSound::get($id);
        $res = $shop_sound_detail->delete();
        if ($res){
            $this->success('删除成功');
        }
    }

    //设备信息
    public function detail()
    {
        $id = input('id',0);
        $shop_sound_detail  = ShopSound::get($id);

        $this->success('',$shop_sound_detail);
    }


    //设备列表
    public function lists()
    {
        $list = ShopSound::where(['shop_id'=>$this->shopauth->shop_id])->order('createtime desc')->select();
        $this->success('',$list);
    }

}